package com.example.scrawldemo.util;

import android.app.Activity;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import org.json.JSONObject;

import java.util.Map;

public class MyOkGoHelper {



    public static void post(final Activity activity, String uri, Map<String, Object> params, final Objectcallback callback){
        JSONObject jsonObject = new JSONObject(params);

        OkGo.<String>post(uri).tag(activity)
                .upJson(jsonObject)
                .headers("Content-Type","application/json").
                headers("uid", "512")  .headers("token", "O5qsq9gMz02ZxVNVGq0vsWJVjLR7zMJqy4cEccFSpTJZ3quqf35s3TUCZHp8Um7dYjdrrXpKzScluMUPdrsh9apnl10jhTTuPB5PfXT1qjVxZCowE0Y8gVaIDJxrKgRz").
                headers("terminal-Type", "1")
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(final Response<String> response) {
                        //请求成功
                        String body = response.body();
                        if (callback != null) {
                            callback.onsuccess(body);
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        String body = response.body();

                        callback.onFalia(0, body);
                    }
                });


    }

    //
    public interface Objectcallback {
        void onsuccess(String st);

        void onFalia(int code, String errst);

    }
}
